package com.cheng.io.input;

import com.cheng.io.entity.Student;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * 将自定义类型对象反序列化为Java对象
 * 每次反序列化会根据类名+serialVersionUID来判断是否是同一个类
 * 如果这个类是合法的，没有问题建议将这个类的serialVersionUID写死
 */
public class ObjectInputStreamTest03 {
    public static void main(String[] args) {
        try (
                ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("io/resources/student"));
        ) {
            Object object = objectInputStream.readObject();
            if (object instanceof Student) System.out.println(object);

        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
